﻿package com.athena.process
{
	import com.athena.controller.LQAGItemController;
	import flash.display.MovieClip;
	import flash.display.*;
	import flash.text.TextFormat;
	import flash.utils.*;
	import flash.events.*;
	import com.adobe.serialization.json.JSON;
	import com.athena.controller.MailItemController;
	/**
	 * ...
	 * @author ...
	 */
	public class LQAGFunction 
	{
		public static var arrLQ : Array ;// = [4000, 12000, 20000, 40000, 100000, 350000, 800000, 1920000, 6000000] ;
		public static var arrAG : Array ;// = [4000, 12000, 20000, 40000, 100000, 350000, 800000, 1920000, 6000000] ;
		public static var arrConvert : Array = new Array() ;
		public static function LQReceive(str : String) {
			arrLQ = new Array() ;
			arrAG = new Array() ;
			var arr : Array = (JSON.decode(str) as Array) ;
			for (var i:int = 0; i < arr.length; i++) 
			{
				arrLQ.push(arr[i].LQ) ;
				arrAG.push(arr[i].AG) ;
			}
			if (Cocaro.mainStage_mc.currentFrame == 3)
				Init() ;
		}
		public static function Init() {
			arrConvert = new Array() ;
			if (arrLQ == null) return ;
			////Cocaro.tf.appendText("==>Init") ;
			for (var i:int = 0; i < arrLQ.length; i++) 
			{
				////Cocaro.tf.appendText("==>LQ:" + arrLQ[i]) ;
				var mc : MovieClip = MovieClip(new LQAG()) ;
				var div : int = (int)(arrConvert.length / 3) ;
				var mod : int = arrConvert.length % 3 ;
				mc.x = 180 * mod ;
				mc.y = 85 * div ;
				mc.name = "ConvertLQAG" ;
				var obj : Object = new Object() ;
				obj.LQ = arrLQ[i] ;
				obj.AG = arrAG[i] ;				
				new LQAGItemController(mc, obj) ;
				arrConvert.push(obj) ;
				Cocaro.mainStage_mc.LQAG_mc.addChild(mc) ;
			}
			if (Cocaro.tabDefault == 1) {			
				Cocaro.mainStage_mc.btnLQAG.gotoAndStop(2) ;
				Cocaro.mainStage_mc.btnNew.gotoAndStop(1) ;
				Cocaro.mainStage_mc.btnDG.gotoAndStop(1) ;
				Cocaro.mainStage_mc.btnCT.gotoAndStop(1) ;
				Cocaro.mainStage_mc.New_mc.visible = false;
				Cocaro.mainStage_mc.CT_mc.visible = false ;
				Cocaro.mainStage_mc.DG_mc.visible = false ;
				Cocaro.mainStage_mc.LQAG_mc.visible = true ;
			} else if (Cocaro.tabDefault == 3) {
				Cocaro.mainStage_mc.btnNew.gotoAndStop(2) ;
				Cocaro.mainStage_mc.btnDG.gotoAndStop(1) ;
				Cocaro.mainStage_mc.btnCT.gotoAndStop(1) ;
				Cocaro.mainStage_mc.btnLQAG.gotoAndStop(1) ;
				Cocaro.mainStage_mc.New_mc.visible = true ;
				Cocaro.mainStage_mc.CT_mc.visible = false ;
				Cocaro.mainStage_mc.DG_mc.visible = false ;
				Cocaro.mainStage_mc.LQAG_mc.visible = false ;
				TopFunction.DisplayNew() ;
			}
		}
		
		public static function LQAGConvert(obj : Object) {
			var LQConvert : int = Cocaro.currPlayer.MarkLQ - obj.LQ ;
			BasicFunction.ShowAlert("Bạn đã chuyển thành công " + LQConvert + " sang AG, Chúc bạn chơi Game vui vẻ!") ;
			Cocaro.currPlayer.MarkLQ = obj.LQ ;
			Cocaro.currPlayer.Mark = obj.AG ;
			Cocaro.mainStage_mc.Profile_mc.Mark_txt.text = BasicFunction.numberFormat(Cocaro.currPlayer.Mark, 0, false, true) + " AG";		
			Cocaro.mainStage_mc.Profile_mc.MarkLQ_txt.text = BasicFunction.numberFormat(Cocaro.currPlayer.MarkLQ, 0, false, true) + " LQ";
			var positionKhung : int = 1 ;
			if ((Cocaro.currPlayer.VIP > Cocaro.vip) || ((Cocaro.currPlayer.VIP == Cocaro.vip) && (Cocaro.currPlayer.Mark > 10000000)) 
				|| ((Cocaro.currPlayer.VIP == Cocaro.vip - 1) && (Cocaro.currPlayer.Mark > 20000000)) 
				|| ((Cocaro.currPlayer.VIP == Cocaro.vip - 2) && (Cocaro.currPlayer.Mark > 50000000))) {
				positionKhung = 3 ;
				Cocaro.formatAvatar_Name.color = 0xFFFFFF ;
			} else {
				Cocaro.formatAvatar_Name.color = 0xFFFF00 ;
				if ((Cocaro.currPlayer.VIP > Cocaro.vipSilver) || ((Cocaro.currPlayer.VIP == Cocaro.vipSilver) && (Cocaro.currPlayer.Mark > 10000000)) 
				|| ((Cocaro.currPlayer.VIP == Cocaro.vipSilver - 1) && (Cocaro.currPlayer.Mark > 20000000)) 
				|| ((Cocaro.currPlayer.VIP == Cocaro.vipSilver-2) && (Cocaro.currPlayer.Mark > 50000000)))		
					positionKhung = 2 ;
			}
			Cocaro.mainStage_mc.Profile_mc.Name_txt.setTextFormat(Cocaro.formatAvatar_Name) ;
			Cocaro.mainStage_mc.Profile_mc.Mark_txt.setTextFormat(Cocaro.formatAvatar_Mark) ;	
			Cocaro.mainStage_mc.Profile_mc.MarkLQ_txt.setTextFormat(Cocaro.formatAvatar_MarkLQ) ;
			Cocaro.mainStage_mc.Profile_mc.BG_Avatar.gotoAndStop(positionKhung) ;
		}
	}
	
}